package org.tinygame.herostory.model;

import java.util.Collection;
import java.util.HashMap;
import java.util.Map;
import java.util.concurrent.ConcurrentHashMap;

/**
 * @author anan
 * @create 2022-05-01 23:43
 */
public final class UserManager {
    static final private Map<Integer, User> _userMap = new ConcurrentHashMap<>();

    /**
     * 私有化默认构造器
     */
    private UserManager(){}

    /**
     * 添加用户
     */
    static public void addUser(User u){
        if(null != u){
            _userMap.putIfAbsent(u.userId, u);
        }
    }

    /**
     * 移除用户
     */
    static public void removeByUserId(int userId){
            _userMap.remove(userId);
    }

    /**
     * 根据用户id获取用户
     * @return
     */
    static public User getByUserId(int userId){return _userMap.get(userId);}

    static public Collection<User> listUser(){
        return _userMap.values();
    }
}
